package com.wangp.mywrite.a_jvm.ch04;

public class HelloByteCode {

    public static void main(String[] args) {
        HelloByteCode obj = new HelloByteCode();
    }
}

/*
 * 反编译出来的代码：
 * Compiled from "HelloByteCode.java"
 * public class com.wangp.mywrite.a_jvm.ch04.HelloByteCode {
 *   public com.wangp.mywrite.a_jvm.ch04.HelloByteCode();
 *     Code:
 *        0: aload_0
 *        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *        4: return
 *
 *   public static void main(java.lang.String[]);
 *     Code:
 *        0: new           #2                  // class com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *        3: dup
 *        4: invokespecial #3                  // Method "<init>":()V
 *        7: astore_1
 *        8: return
 * }
 */

/*
 * 解读字节码：

 *   public com.wangp.mywrite.a_jvm.ch04.HelloByteCode();
 *     Code:
 *        0: aload_0
 *        1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *        4: return
 *   该段为无参构造函数。
 *
 *   public static void main(java.lang.String[]);
 *     Code:
 *        0: new           #2                  // class com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *        3: dup
 *        4: invokespecial #3                  // Method "<init>":()V
 *        7: astore_1
 *        8: return
 *   该段为 main 方法创建一个实例，然后 return。
 */

/* verbose 反编译：
 * Classfile /D:/project/MyWriter/src/main/java/com/wangp/mywrite/a_jvm/ch04/HelloByteCode.class
 *   Last modified 2022-10-19; size 473 bytes
 *   MD5 checksum 874762b544f7a177cafcfe5d1bcd1742
 *   Compiled from "HelloByteCode.java"
 * public class com.wangp.mywrite.a_jvm.ch04.HelloByteCode
 *   minor version: 0
 *   major version: 52
 *   flags: ACC_PUBLIC, ACC_SUPER
 * Constant pool:
 *    #1 = Methodref          #4.#19         // java/lang/Object."<init>":()V
 *    #2 = Class              #20            // com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *    #3 = Methodref          #2.#19         // com/wangp/mywrite/a_jvm/ch04/HelloByteCode."<init>":()V
 *    #4 = Class              #21            // java/lang/Object
 *    #5 = Utf8               <init>
 *    #6 = Utf8               ()V
 *    #7 = Utf8               Code
 *    #8 = Utf8               LineNumberTable
 *    #9 = Utf8               LocalVariableTable
 *   #10 = Utf8               this
 *   #11 = Utf8               Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 *   #12 = Utf8               main
 *   #13 = Utf8               ([Ljava/lang/String;)V
 *   #14 = Utf8               args
 *   #15 = Utf8               [Ljava/lang/String;
 *   #16 = Utf8               obj
 *   #17 = Utf8               SourceFile
 *   #18 = Utf8               HelloByteCode.java
 *   #19 = NameAndType        #5:#6          // "<init>":()V
 *   #20 = Utf8               com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *   #21 = Utf8               java/lang/Object
 * {
 *   public com.wangp.mywrite.a_jvm.ch04.HelloByteCode();
 *     descriptor: ()V
 *     flags: ACC_PUBLIC
 *     Code:
 *       stack=1, locals=1, args_size=1
 *          0: aload_0
 *          1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *          4: return
 *       LineNumberTable:
 *         line 3: 0
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       5     0  this   Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 *
 *   public static void main(java.lang.String[]);
 *     descriptor: ([Ljava/lang/String;)V
 *     flags: ACC_PUBLIC, ACC_STATIC
 *     Code:
 *       stack=2, locals=2, args_size=1
 *          0: new           #2                  // class com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *          3: dup
 *          4: invokespecial #3                  // Method "<init>":()V
 *          7: astore_1
 *          8: return
 *       LineNumberTable:
 *         line 6: 0
 *         line 7: 8
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       9     0  args   [Ljava/lang/String;
 *             8       1     1   obj   Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 * }
 * SourceFile: "HelloByteCode.java"
 *
 */

/* verbose 反编译解析：
 * Classfile /D:/project/MyWriter/src/main/java/com/wangp/mywrite/a_jvm/ch04/HelloByteCode.class
 *   Last modified 2022-10-19; size 473 bytes
 *   MD5 checksum 874762b544f7a177cafcfe5d1bcd1742
 *   Compiled from "HelloByteCode.java"
 * public class com.wangp.mywrite.a_jvm.ch04.HelloByteCode
 *   minor version: 0
 *   major version: 52
 *   flags: ACC_PUBLIC 【public 类】, ACC_SUPER 【super 调用】
 * Constant pool:
 *    #1 = Methodref          #4.#19         // java/lang/Object."<init>":()V
 *    【#1 常量编号，该文件中其他地方可以引用】
 *    【= 等号就是分隔符.】
 *    【Methodref 表明这个常量指向的是一个方法；具体是哪个类的哪个方法呢? 类指向的 #4, 方法签名指向的 #19; 当然双斜线注释后面已经解析出来可读性比较好的说明了。】
 *    #2 = Class              #20            // com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *    #3 = Methodref          #2.#19         // com/wangp/mywrite/a_jvm/ch04/HelloByteCode."<init>":()V
 *    #4 = Class              #21            // java/lang/Object
 *    #5 = Utf8               <init>
 *    #6 = Utf8               ()V
 *    #7 = Utf8               Code
 *    #8 = Utf8               LineNumberTable
 *    #9 = Utf8               LocalVariableTable
 *   #10 = Utf8               this
 *   #11 = Utf8               Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 *   #12 = Utf8               main
 *   #13 = Utf8               ([Ljava/lang/String;)V
 *   #14 = Utf8               args
 *   #15 = Utf8               [Ljava/lang/String;
 *   #16 = Utf8               obj
 *   #17 = Utf8               SourceFile
 *   #18 = Utf8               HelloByteCode.java
 *   #19 = NameAndType        #5:#6          // "<init>":()V
 *   #20 = Utf8               com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *   #21 = Utf8               java/lang/Object
 * {
 *   public com.wangp.mywrite.a_jvm.ch04.HelloByteCode();
 *     descriptor: ()V
 *     flags: ACC_PUBLIC
 *     Code:
 *       stack=1, locals=1, args_size=1     【为什么构造函数的参数不为一？这是因为在 Java 中, 如果是静态方法则没有 this 引用。 对于非静态方法， this 将被分配到局部变量表的第 0 号槽位中】
 *          0: aload_0
 *          1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *          4: return
 *       LineNumberTable:
 *         line 3: 0
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       5     0  this   Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 *
 *   public static void main(java.lang.String[]);
 *     descriptor: ([Ljava/lang/String;)V      【小括号内是入参信息/形参信息；左方括号标识数组；L表示对象，其后面java/lang/String为类名称；V表示返回值void;】
 *     flags: ACC_PUBLIC, ACC_STATIC           【public static】
 *     Code:
 *       stack=2, locals=2, args_size=1        【栈深度是2，需要局部变量表保留2个槽位，方法的参数个数是1】
 *          0: new           #2                  // class com/wangp/mywrite/a_jvm/ch04/HelloByteCode
 *          3: dup
 *          4: invokespecial #3                  // Method "<init>":()V
 *          7: astore_1
 *          8: return
 *       LineNumberTable:
 *         line 6: 0
 *         line 7: 8
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0       9     0  args   [Ljava/lang/String;
 *             8       1     1   obj   Lcom/wangp/mywrite/a_jvm/ch04/HelloByteCode;
 * }
 * SourceFile: "HelloByteCode.java"
 *
 */